package com.ten.course.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ten.common.core.entity.EduSubject;
import com.ten.common.core.vo.Result;
import com.ten.course.service.CourseSubjectService;
import com.ten.course.vo.CourseSubjectVo;
import com.ten.course.vo.SubjectInsertVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：张成（3092211427@qq.com）
 * @date ：Created in 2022/12/7 20:14
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/core/subject")
@Api(tags = "课程分类api接口")
public class CourseSubjectController {

    @Autowired
    private CourseSubjectService courseSubjectService;

    @ApiOperation(value = "根据条件进行分页")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前页码", name = "pageCurrent"),
            @ApiImplicitParam(value = "展示显示的页数", name = "pageSize")
    })
    @PostMapping("findSubject/{pageCurrent}/{pageSize}")
    public Result<Page<EduSubject>> findSubject(
            @PathVariable Integer pageCurrent,
            @PathVariable Integer pageSize,
            @RequestBody CourseSubjectVo courseSubjectVo) {
        return courseSubjectService.findSubject(pageCurrent, pageSize, courseSubjectVo);
    }

    /**
     * 根据id和parentId修改status_id
     *
     * @param eduSubject 课程分类实体类，用于接收id，父id，和statusId
     * @return
     */
    @ApiOperation(value = "根据id和parentId修改课程分类的正常或者禁用状态")
    @PostMapping("changeStatusId")
    public Result changeStatusId(@RequestBody EduSubject eduSubject) {
        return courseSubjectService.changeStatusId(eduSubject);
    }

    /**
     * 根据课程分类添加Vo类添加课程分类
     *
     * @param subjectInsertVo 课程分类添加Vo类
     * @return
     */
    @ApiOperation(value = "根据课程分类插入Vo类添加课程分类")
    @PostMapping("insertSubject")
    public Result insertSubject(@RequestBody SubjectInsertVo subjectInsertVo) {
        return courseSubjectService.insertSubject(subjectInsertVo);
    }

    /**
     * 根据课程分类id删除课程分类
     *
     * @param eduSubject
     * @return
     */
    @ApiOperation(value = "根据课程分类id删除课程分类")
    @PostMapping("deleteSubject")
    public Result deleteSubject(@RequestBody EduSubject eduSubject) {
        return courseSubjectService.deleteSubject(eduSubject);
    }

    /**
     * 根据课程id修改edusubject中的信息
     * @param eduSubject
     * @return
     */
    @ApiOperation(value = "根据课程id修改edusubject中的信息")
    @PostMapping("updateSubject")
    public Result updateSubject(@RequestBody EduSubject eduSubject) {
        return courseSubjectService.updateSubject(eduSubject);
    }

    /*************************客户端controller*********************/

    /**
     * 根据pid查询父亲的id，返回父亲的id到前端
     *
     * @param pid
     * @return
     */
    @ApiOperation(value = "根据pid查询父亲的pid，返回父亲的pid到前端")
    @GetMapping("findPidById/{pid}")
    public Result<String> findPidById(@PathVariable String pid) {
        return courseSubjectService.findPidById(pid);
    }

    /**
     * 获取课程分类信息
     *
     * @return
     */
    @ApiOperation(value = "获取课程分类信息")
    @PostMapping("findSubjectByStatus")
    public Result<List<EduSubject>> findSubjectByStatus() {
        return courseSubjectService.findSubjectByStatus();
    }

    /**
     * 获取所有的课程分类列表
     * @return
     */
    @ApiOperation(value= "获取所有的课程分类列表")
    @PostMapping("getAllMenu")
    public Result<List<EduSubject>> getAllMenu(){
        return courseSubjectService.getAllMenu();
    }

}